package leetcode199

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func rightSideView(root *TreeNode) []int {
	var res []int
	if root == nil {
		return res
	}

	loopNode := [][]*TreeNode{{root}}
	i := 0
	for {
		var (
			temp     []*TreeNode
			curValue int
		)
		if i >= len(loopNode) || len(loopNode[i]) == 0 {
			return res
		}

		for _, node := range loopNode[i] {
			curValue = node.Val
			if node.Left != nil {
				temp = append(temp, node.Left)
			}
			if node.Right != nil {
				temp = append(temp, node.Right)
			}
		}
		i++
		loopNode = append(loopNode, temp)
		res = append(res, curValue)
	}
}
